<%@page import="com.itsm.v17.entity.PrizeActivity"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.List"%>
<%@ page pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String message=request.getAttribute("message")+"";
List list=(List)request.getAttribute("list");
if(list==null){list=new LinkedList();}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>抽奖活动</title>
<link href="<%=basePath%>css/home.css" type="text/css" rel="stylesheet" />
<script src="<%=basePath%>js/DatePicker/WdatePicker.js" type="text/javascript"></script>
<link href="<%=basePath%>js/DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<script src="<%=basePath%>itsm/js/ajax.js"></script>
<script src="<%=basePath%>itsm/js/ajax.form.js"></script>
<script src="<%=basePath%>itsm/js/formValidate.js"></script>
<script src="<%=basePath%>itsm/js/select.js"></script>
<script src="<%=basePath%>itsm/js/reSet.js"></script>
<style>
.tableblue00 td{
padding:5px;
}
</style>
</head>
<body style="padding:5px;margin:0px;">
<table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00">
                            <tbody>
                            <tr class="bbzxbg2">
                              <td colspan=3 >
                              	 &nbsp; &nbsp;
                              	 <a class="actionbutton"  href='javascript:;' onclick="create()" class="menudiv" style="margin-right: 10px;">新建</a>
                              	 &nbsp;&nbsp;
                              </td>
                            </tr></tbody>
          </table> <br/>
                     
 <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00">
   <tbody>
   <tr class="bbzxbg2">
                <td width="20%">活动名称</td>
                <td align="left">开始时间</td>
                <td align="left">结束时间</td>
                <td align="left">状态</td>
                <td align="left">操作</td>
         </tr>
   <%
   		for(int i=0;i<list.size();i++)
   		{
   			PrizeActivity activity=(PrizeActivity)list.get(i);
   			System.out.println("name="+activity.getName()+",status="+activity.getStatus());
   			%>
   				<tr class="bbzxbg2">
                <td width="20%"><%=activity.getName()%></td>
                <td align="left"><%=activity.getStartDate()%></td>
                <td align="left"><%=activity.getEndDate()%></td>
                <td align="left"><%if("0".equals(activity.getStatus())){out.print("非活动");}else{out.print("活动");}%></td>
                <td align="left">
                	
                	<a href="javascript:;" onclick="edit('<%=activity.getId()%>','<%=activity.getName()%>','<%=activity.getStartDate()%>','<%=activity.getEndDate()%>','<%=activity.getStatus()%>')">编辑</a>
                	&nbsp;&nbsp;
                	<a href="javascript:;" onclick="deletes('<%=activity.getId()%>','<%=activity.getName()%>',this)">删除</a>
                	&nbsp;&nbsp;
                	<a href="<%=path%>/itsm17/prize/activity/adminPrize?pid=<%=activity.getId()%>">奖品管理</a>
                	&nbsp;&nbsp;
                	
                	</td>
         </tr>
   			<%
   		}
   %>
          <tr class="bbzxbg2">
                <td colspan=5 align="left">&nbsp;<%=message%></td>
         </tr>               
 </tbody>
</table>      <br/>               
                     
  <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00" id="datafrom" style="display:none;" >
                            <tbody>
                            <tr class="bbzxbg2">
                              <td colspan=3 >
                              	<input type="hidden" name="id" id="id" />
                              	 活动名称： <input type="text" name="name" id="name" value=""  
                              	 require=true min=1 message="活动名称必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 开始时间： <input type="text" name="startDate" id="startDate" value=""  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" 
                              	 require=true min=1 message="开始时间必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 结束时间： <input type="text" name="endDate" id="endDate" value="" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" 
                              	 require=true min=1 message="结束时间必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 状态:<select id="status" name="status" >
                              	 	<option value="0">非活动</option>
                              	 	<option value="1">活动</option>
                              	 </select>
                              	 
                              	 <a class="actionbutton"  href='javascript:;' onclick="save()" class="menudiv" style="margin-right: 10px;">保存</a>
                              	 &nbsp;&nbsp;
                              	 <span id="message"></span>
                              </td>
                            </tr></tbody>
          </table>
                     <br/>      
<script>
function create()
{
	get("message").innerHTML='';
	reSet("datafrom");
	show("datafrom");
}
function save()
{
	get("message").innerHTML='';
	if(!formValidate("datafrom")){return;}
	get("message").innerHTML='正在提交...';	
	new ajaxForm({'url':'<%=path%>/itsm17/prize/activity/save','form':'datafrom','success':function(data)
		{
			var json=toJson(data);
			if(json.result)
			{
				location.reload();
			}else
			{
				get("message").innerHTML='<font color=red>'+json.message+'</font>';	
			}
		}});	
}
function edit(id,name,startDate,endDate,status)
{
	get("message").innerHTML='';
	show("datafrom");
	get("id").value=id;
	get("name").value=name;
	get("startDate").value=startDate;
	get("endDate").value=endDate;
	setSelectSelected("status",status);
}
var isDelete=false;
function deletes(id,name,obj)
{
	if(isDelete){return;}
	if(confirm("确定删除?"+name))
	{
		isDelete=true;
		obj.innerHTML="正在删除...";
		new ajax({'url':'<%=path%>/itsm17/prize/activity/delete','params':'id='+id,'success':function(data)
			{
				isDelete=false;
				var json=toJson(data);
				if(json.result)
				{
					location.reload();
				}else
				{
					alert(json.message);	
				}
			}});
	}
}
</script>
</body>
</html>